home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cgazv5n4.arc / STRNGPTR.H < prev    next >
C/C++ Source or Header  |  1991-09-23  |  562b  |  19 lines

  1. //--- STRNGPTR.H ------------------------- Listing 5 -----------
  2. // Hiding a string pointer inside a class
  3. // by Bruce Eckel. See Listing 1 for copyright information.
  4. //--------------------------------------------------------------
  5.  
  6. #ifndef STRINGPTR_H_
  7. #define STRINGPTR_H_
  8. #include "stringc.h"
  9.  
  10. class string_ptr {
  11.   string * s;
  12. public:
  13.   string_ptr() : s(new string("")) {}
  14.   string_ptr(char * st) : s(new string(st)) {}
  15.   ~string_ptr() { delete s; }
  16.   string* operator->() { return s; }  // This operates unusually
  17. };
  18.  
  19. #endif // STRINGPTR_H_